﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Intrinsics.Arm;
using System.Text;
using System.Threading.Tasks;

public class Solution213
{
    public int Rob(int[] nums)
        
    {
        
        int len=nums.Length;
        if (len == 1)
        {
            return nums[0];
        }


        int[] woHead=new int[nums.Length-1];
        //去掉第一个
        Array.Copy(nums, 1, woHead, 0, len - 1);
        int headRes= PreRob(woHead);
        Console.WriteLine("headRes: " + headRes);
        int[] woNail=new int[nums.Length-1];
        //去掉最后一个
        Array.Copy(nums, 0, woNail, 0, len - 1);
        int NailRes= PreRob(woNail);

        Console.WriteLine("NailRes: " + NailRes);
        return Math.Max(NailRes, headRes);







    }


    public int PreRob(int[] nums)


    {

        for(int i=0; i<nums.Length; i++)
        {
            Console.WriteLine("Maximum amount: " + nums[i]);
        }
        int[] dp=new int[nums.Length];

        int len = nums.Length;
        if (len == 0)
        {
            return 0;
        }

        if (len == 1)
        {
            dp[0]=nums[0];
           
        }
        if(len > 1)
        {
            dp[0] = nums[0];
            dp[1] = Math.Max(nums[0], nums[1]);
            Console.WriteLine(" dp[1] : " + dp[1]);
            //1，本次打劫，上次肯定不能打劫,看上上一次的结果
            //2，本次不打劫，看上一次的结果

            for (int i = 2; i < nums.Length; i++)
            {
                dp[i] = Math.Max(dp[i - 1], dp[i - 2] + nums[i]);
                Console.WriteLine(" [i]: "+i+ "dp[i]:" + dp[i]);
            }

        }
        
      
        return dp[len - 1];
       

    }

}
class program213
{
    static void Main213()
    {
        Solution213 solution = new Solution213();

        int[] nums = { 1, 2, 3, 1 };
        int result = solution.Rob(nums);
        Console.WriteLine("Maximum amount: " + result);
        Console.ReadKey();


    }
}
